home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-20 | 53.7 KB | 1,709 lines |
- Newsgroups: comp.sources.misc
- From: kirsch@usasoc.soc.mil (David Kirschbaum)
- Subject: v23i090: zip - Portable zip v1.0, Part03/09
- Message-ID: <1991Oct21.042104.7918@sparky.imd.sterling.com>
- X-Md4-Signature: 41414f8ff5213b92238d6f33f9e09e28
- Date: Mon, 21 Oct 1991 04:21:04 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: kirsch@usasoc.soc.mil (David Kirschbaum)
- Posting-number: Volume 23, Issue 90
- Archive-name: zip/part03
- Environment: UNIX, Minix, MSDOS, OS/2, VMS
-
- #! /bin/sh
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # Contents: MANIFEST ship.c util.c
- # Wrapped by kent@sparky on Sun Oct 20 22:58:52 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 3 (of 9)."'
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(1447 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X Contents 1
- X History 7
- X INFOZIP.WHO 2
- X MANIFEST 1 This shipping list
- X README 1
- X crypt.h 1
- X dir_os2.c 2
- X dir_os2.h 1
- X doturboc.bat 1
- X fileio.c 9
- X globals.c 1
- X im_bits.c 2
- X im_ctree.c 10
- X im_lm.asm 3
- X im_lmat.c 6
- X implode.c 2
- X implode.h 2
- X makecrc.c 1
- X makefile 1
- X makefile.bor 1
- X makefile.msc 1
- X makefile.os2 1
- X makefile.pwc 1
- X makevms.com 1
- X revision.h 1
- X ship.c 8
- X ship.def 1
- X shrink.c 3
- X tailor.h 1
- X tempf.c 1
- X tempf.h 1
- X util.c 3
- X zip.1 5
- X zip.c 6
- X zip.def 1
- X zip.doc 5
- X zip.h 2
- X zip.prj 1
- X ziperr.h 1
- X zipfile.c 4
- X zipnote.c 2
- X zipsplit.c 4
- X zipup.c 3
- END_OF_FILE
- if test 1447 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'ship.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'ship.c'\"
- else
- echo shar: Extracting \"'ship.c'\" \(38393 characters\)
- sed "s/^X//" >'ship.c' <<'END_OF_FILE'
- X/* ship.c -- Not copyrighted 1991 Mark Adler */
- X
- X#define SHIPVER "ship version 1.0 September 29, 1991 Mark Adler"
- X
- X/* Command for mailing (-m): the %s's are, in order, the subject prefix,
- X the part number (always of the form "partnnnn"), the subject suffix
- X (empty or " (last)" if the last part), the mailing address, and the
- X name of the temporary file begin mailed. The command "Mail" is for BSD
- X systems. You may need to change it to "mailx" for System V Unix, using
- X the compile option "-DMAILX". Also, on Sperry (Unisys?) SysV.3 systems,
- X you might try the command name "v6mail". */
- X
- X#ifdef DIRENT /* If compiled with zip, DIRENT implies System V */
- X# define MAILX
- X#endif /* DIRENT */
- X
- X#ifdef sun /* Except Sun's use DIRENT, but have Mail */
- X# ifdef MAILX
- X# undef MAILX
- X# endif /* MAILX */
- X#endif /* sun */
- X
- X#ifdef sgi /* Silicon Graphics that way too */
- X# ifdef MAILX
- X# undef MAILX
- X# endif /* MAILX */
- X#endif /* sgi */
- X
- X#ifdef VMS
- X# define TMPNAME "_SXXXXXX."
- X# define MAILCMD "mail %s /subj=\"%s %s%s\" \"%s\""
- X# define PATHCUT ']'
- X#else /* !VMS */
- X# define TMPNAME "_SXXXXXX"
- X# ifdef MAILX
- X# define MAILCMD "mailx -s \"%s %s%s\" \"%s\" < %s"
- X# else /* !MAILX */
- X# define MAILCMD "Mail -s \"%s %s%s\" \"%s\" < %s"
- X# endif /* ?MAILX */
- X# define PATHCUT '/'
- X#endif /* ?VMS */
- X
- X/*
- X
- XSHIP -
- X
- X Ship is a program for sending binary files through email. It is designed
- X to supplant uuencode and uudecode. Ship encodes approximately 6.23 bits
- X per character mailed, compared to uuencode's 5.73 bits per character.
- X
- X Ship also has these features: a 32-bit CRC check on each file; automatic
- X splitting of the ship output into multiple, smaller files for speedier
- X mailing; automatic mailing of ship's output, with subject lines for
- X multiple parts; and a check on the sequence of parts when unshipping.
- X
- X Usage:
- X
- X ship [-nnn] [-m address] [-s subject] file ...
- X
- X where nnn is the maximum number of K bytes for each output file, address
- X is the address to send mail to, subject is a Subject" line prefix, and
- X file ... is a list of files to ship. If no options are given, ship
- X outputs to stdout. The simplest use is:
- X
- X ship foo > x
- X
- X where foo is converted into the mailable file, x.
- X
- X When -nnn is specified, but -m is not, ship writes to the files
- X part0001, part0002, etc., where each file has nnn or less K bytes. For
- X example:
- X
- X ship -25 bigfoo
- X
- X will write however many 25K byte or less ship files is needed to contain
- X bigfoo. If, say, six files are needed, then the files part0001 to part0006
- X will be written.
- X
- X When using -m, nothing is written, either to files or to stdout; rather,
- X the output is mailed to the specified address. If -nnn is also specified,
- X then the parts are mailed separately with the subject lines part0001, etc.
- X If -nnn is not specified, then only one part (the whole thing) is mailed
- X with the subject line "part0001". For example:
- X
- X ship -25 -m fred bigfoo
- X
- X will mail the six parts of bigfoo to fred.
- X
- X Any number of files can be shipped at once. They become part of one long
- X ship stream, so if, for example -25 is specified, all but the last part
- X will have about 25K bytes. For example:
- X
- X ship -25 -m fred fee fi fo fum
- X
- X will send the files fee, fi, fo, and fum to fred.
- X
- X Fred will get several mail messages with the subject lines part0001, etc.
- X He can then save those messages as the files, say, p1, p2, p3, ...
- X Then he can use the command:
- X
- X ship -u p?
- X
- X to recreate bigfoo, or fee fi fo and fum, depending on what he was sent.
- X If Fred saved the wrong numbers, ship will detect this and report a
- X sequence error.
- X
- X Note: there is enough information in the shipped parts to determine the
- X correct sequence. A future version of ship will prescan the files to
- X determine the sequence, and then process them in the correct order.
- X
- X If a file being received already exists, ship -u will report an error
- X and exit. The -o option avoids this and allows ship to overwrite existing
- X files. The -o option must follow the -u option:
- X
- X ship -u -o p?
- X
- X In addition to the -u option, ship will unship if it sees that its name is
- X unship. On Unix systems, this can be done simply by linking the executable
- X to unship:
- X
- X ln ship unship
- X
- X Ship can also be used as a filter. The special file name "-" means stdin.
- X For example:
- X
- X tar covf - foodir | compress | ship -25 -m fred -
- X
- X will tar the directory foodir, compress it, and ship it to fred in 25K byte
- X pieces. Then, after Fred saves the files as p01, etc. at the other, end,
- X he can:
- X
- X ship -u p? | zcat | tar xovf -
- X
- X which will recreate the directory foobar and its contents. ship -u knows
- X to write to stdout, since the original ship put the special file name "-"
- X in the first part.
- X
- X Ship uses a base 85 coding that needs 32-bit multiplication and division.
- X This can be slow on 16-bit machines, so ship provides a fast encoding
- X method by specifying the -f option. This method is somewhat faster even
- X on 32-bit machines, and has approximately a 1% penalty in the size of the
- X encoded result (-f gives 6.26 bits per character, on the average). The -f
- X option need only be used when shipping--unshipping (ship -u) automatically
- X detects the encoding used. For example:
- X
- X ship -f -25 -m fred foo
- X
- X will send foo to fred in 25K byte pieces using the fast encoding method.
- X You don't need to tell Fred, since ship -u will figure that out for him.
- X
- X The fast encoding method is probabilistic, so it's possible for the size
- X penalty to be worse than 1%, and it's also possible for the fast encoding
- X to produce a smaller result than base 85 encoding would, all depending on
- X the data.
- X
- X The -q option can be used with either ship or unship (ship -u) for quiet
- X operation--informational messages are inhibited.
- X
- X You can find out the version of ship and get the command usage by using
- X "ship -h" or "ship -?". The version number and date and help will be
- X printed, and ship will exit (the rest of the command line is ignored).
- X
- X Acknowledgements:
- X
- X The hard-arithmetic coding algorithm was blatantly stolen from Peter
- X Gutmann's pgencode/pgdecode programs posted on comp.compression, with
- X modifications to use 86 instead of 94 characters, and to make zeros encode
- X better than, rather than worse than other bytes. (As Stravinsky once said:
- X "Mediocre composers plagiarize. Great composers steal.")
- X
- X*/
- X
- X/* tailor.h -- Not copyrighted 1991 Mark Adler */
- X
- X/* const's are inconsistently used across ANSI libraries--kill for all
- X header files. */
- X#define const
- X
- X
- X/* Use prototypes and ANSI libraries if __STDC__ */
- X#ifdef __STDC__
- X# ifndef PROTO
- X# define PROTO
- X# endif /* !PROTO */
- X# define MODERN
- X#endif /* __STDC__ */
- X
- X
- X/* Use prototypes and ANSI libraries if Silicon Graphics */
- X#ifdef sgi
- X# ifndef PROTO
- X# define PROTO
- X# endif /* !PROTO */
- X# define MODERN
- X#endif /* sgi */
- X
- X
- X/* Define MSDOS for Turbo C as well as Microsoft C */
- X#ifdef __POWERC /* For Power C too */
- X# define __TURBOC__
- X#endif /* __POWERC */
- X#ifdef __TURBOC__
- X# ifndef MSDOS
- X# define MSDOS
- X# endif /* !MSDOS */
- X#endif /* __TURBOC__ */
- X
- X
- X/* Use prototypes and ANSI libraries if Microsoft or Borland C */
- X#ifdef MSDOS
- X# ifndef PROTO
- X# define PROTO
- X# endif /* !PROTO */
- X# define MODERN
- X#endif /* MSDOS */
- X
- X
- X/* Turn off prototypes if requested */
- X#ifdef NOPROTO
- X# ifdef PROTO
- X# undef PROTO
- X# endif /* PROTO */
- X#endif /* NOPROT */
- X
- X
- X/* Used to remove arguments in function prototypes for non-ANSI C */
- X#ifdef PROTO
- X# define OF(a) a
- X#else /* !PROTO */
- X# define OF(a) ()
- X#endif /* ?PROTO */
- X
- X
- X/* Allow far and huge allocation for small model (Microsoft C or Turbo C) */
- X#ifdef MSDOS
- X# ifdef __TURBOC__
- X# include <alloc.h>
- X# else /* !__TURBOC__ */
- X# include <malloc.h>
- X# define farmalloc _fmalloc
- X# define farfree _ffree
- X# endif /* ?__TURBOC__ */
- X#else /* !MSDOS */
- X# define huge
- X# define far
- X# define near
- X# define farmalloc malloc
- X# define farfree free
- X#endif /* ?MSDOS */
- X
- X
- X/* Define MSVMS if either MSDOS or VMS defined */
- X#ifdef MSDOS
- X# define MSVMS
- X#else /* !MSDOS */
- X# ifdef VMS
- X# define MSVMS
- X# endif /* VMS */
- X#endif /* ?MSDOS */
- X
- X
- X/* Define void, voidp, and extent (size_t) */
- X#include <stdio.h>
- X#ifdef MODERN
- X# ifndef M_XENIX
- X# include <stddef.h>
- X# endif /* !M_XENIX */
- X# include <stdlib.h>
- X typedef size_t extent;
- X typedef void voidp;
- X#else /* !MODERN */
- X typedef unsigned int extent;
- X# define void int
- X typedef char voidp;
- X#endif /* ?MODERN */
- X
- X/* Get types and stat */
- X#ifdef VMS
- X# include <types.h>
- X# include <stat.h>
- X#else /* !VMS */
- X# include <sys/types.h>
- X# include <sys/stat.h>
- X#endif /* ?VMS */
- X
- X
- X/* Cheap fix for unlink on VMS */
- X#ifdef VMS
- X# define unlink delete
- X#endif /* VMS */
- X
- X
- X/* For Pyramid */
- X#ifdef pyr
- X# define strrchr rindex
- X# define ZMEM
- X#endif /* pyr */
- X
- X
- X/* File operations--use "b" for binary if allowed */
- X#ifdef MODERN
- X# define FOPR "rb"
- X# define FOPM "r+b"
- X# define FOPW "w+b"
- X#else /* !MODERN */
- X# define FOPR "r"
- X# define FOPM "r+"
- X# define FOPW "w+"
- X#endif /* ?MODERN */
- X
- X
- X/* Fine tuning */
- X#ifndef MSDOS
- X# define BSZ 8192 /* Buffer size for files */
- X#else /* !MSDOS */
- X# define BSZ 4096 /* Keep precious NEAR space */
- X /* BSZ can't be 8192 even for compact model because of 64K limitation
- X * in im_lmat.c. If you run out of memory when processing a large number
- X * files, use the compact model and reduce BSZ to 2048 here and in
- X * im_lm.asm.
- X */
- X#endif /* ?MSDOS */
- X
- X/* end of tailor.h */
- X
- X#ifdef MODERN
- X# include <string.h>
- X#else /* !MODERN */
- X voidp *malloc();
- X long atol();
- X char *strcpy();
- X char *strrchr();
- X#endif /* ?MODERN */
- X
- X/* Library functions not in (most) header files */
- Xchar *mktemp OF((char *));
- Xint unlink OF((char *));
- X
- X#ifdef MSDOS /* Use binary mode for binary files */
- X# include <io.h>
- X# include <fcntl.h>
- X#endif /* MSDOS */
- X
- X
- X#define LNSZ 1025 /* size of line buffer */
- X
- Xtypedef unsigned long ulg; /* 32-bit unsigned integer */
- X
- Xtypedef struct { /* associates a CRC with a file */
- X FILE *f; /* pointer to associated file stream */
- X ulg c; /* CRC register */
- X ulg b; /* four byte buffer */
- X int n; /* buffer count */
- X} cfile;
- X
- X
- X/* Function prototypes */
- X#ifdef MODERN
- X void err(int, char *);
- X cfile *chook(FILE *);
- X char *nopath(char *);
- X void newship(void);
- X void endship(int);
- X void newline(char *);
- X void ship(char *, FILE *);
- X void mkinv(void);
- X void decode(unsigned char *, cfile *);
- X void unship(char **, int, int);
- X void help(void);
- X void main(int, char **);
- X#endif /* MODERN */
- X
- X
- X
- X/* Globals for ship() */
- Xchar sname[9]; /* current ship file name */
- XFILE *sfile; /* current ship file */
- Xulg slns; /* number of lines written to ship file */
- Xulg slmax; /* maximum number of lines per ship file */
- Xint fast; /* true for arithmetic coding, else base 85 */
- Xint mail; /* true if mailing */
- Xchar mpspc[9]; /* prealloced space for prefix */
- Xchar *mprefix = mpspc; /* identification for this mailing */
- Xchar *mdest; /* mail destination */
- Xchar mname[10]; /* temporary file name if mailing */
- Xulg ccnt; /* count of bytes read or written */
- Xint noisy = 1; /* false to inhibit informational messages */
- X
- X
- X
- X/* Errors */
- X#define SE_ARG 1
- X#define SE_FIND 2
- X#define SE_NONE 3
- X#define SE_PART 4
- X#define SE_FORM 5
- X#define SE_CONT 6
- X#define SE_CRC 7
- X#define SE_MAIL 8
- X#define SE_OVER 9
- X#define SE_FULL 10
- X#define SE_MANY 11
- X#define SE_MEM 12
- Xchar *errors[] = {
- X /* 1 */ "invalid argument ",
- X /* 2 */ "could not find ",
- X /* 3 */ "no files received",
- X /* 4 */ "unfinished file ",
- X /* 5 */ "invalid ship format in ",
- X /* 6 */ "wrong sequence for ",
- X /* 7 */ "CRC check failed on ",
- X /* 8 */ "mail command failed: ",
- X /* 9 */ "attempted to overwrite ",
- X /* 10 */ "could not write to ",
- X /* 11 */ "too many output files!",
- X /* 12 */ "out of memory"
- X};
- X
- X
- X/* Set of 86 characters used for the base 85 digits (last one not used), and
- X the 86 character arithmetic coding. Selected to be part of both the ASCII
- X printable characters, and the common EBCDIC printable characters whose
- X ASCII translations are universal. */
- Xunsigned char safe[] = {
- X '{','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',
- X '0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@',
- X 'A','B','C','D','E','F','G','H','I','J','K','L','M',
- X 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_',
- X 'a','b','c','d','e','f','g','h','i','j','k','l','m',
- X 'n','o','p','q','r','s','t','u','v','w','x','y','z','}'};
- X
- X#define LOWSZ (sizeof(safe)-64) /* low set size for fast coding */
- X
- X/* Special replacement pairs--if first of each pair is received, it is
- X treated like the second member of the pair. You're probably
- X wondering why. The first pair is for compatibility with an
- X earlier version of ship that used ! for the base 85 zero digit.
- X However, there exist ASCII-EBCDIC translation tables that don't
- X know about exclamation marks. The second set has mysterious
- X historical origins that are best left unspoken ... */
- Xunsigned char aliases[] = {'!','{','|','+',0};
- X
- X/* Inverse of safe[], filled in by mkinv() */
- Xunsigned char invsafe[256];
- X
- X/* Table of CRC-32's of all single byte values (made by makecrc.c) */
- Xulg crctab[] = {
- X 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
- X 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
- X 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
- X 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
- X 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
- X 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
- X 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
- X 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
- X 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
- X 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
- X 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
- X 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
- X 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
- X 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
- X 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
- X 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
- X 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
- X 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
- X 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
- X 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
- X 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
- X 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
- X 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
- X 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
- X 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
- X 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
- X 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
- X 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
- X 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
- X 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
- X 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
- X 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
- X 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
- X 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
- X 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
- X 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
- X 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
- X 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
- X 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
- X 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
- X 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
- X 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
- X 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
- X 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
- X 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
- X 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
- X 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
- X 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
- X 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
- X 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
- X 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
- X 0x2d02ef8dL
- X};
- X
- X/* Macro to update the CRC shift register one byte at a time */
- X#define CRC(c,b) (crctab[((int)(c)^(int)(b))&0xff]^((c)>>8))
- X
- X
- Xchar *errname = "ship error";
- Xchar *warname = "ship warning";
- X
- Xvoid err(n, m)
- Xint n; /* error number */
- Xchar *m; /* additional error information */
- X{
- X if (n == SE_FIND || n == SE_FULL)
- X perror(errname);
- X fputs(errname, stderr);
- X fputs(": ", stderr);
- X fputs(errors[n - 1], stderr);
- X fputs(m, stderr);
- X putc('\n', stderr);
- X if (*mname)
- X unlink(mname);
- X#ifdef VMS
- X exit(0);
- X#else /* !VMS */
- X exit(n);
- X#endif /* ?VMS */
- X}
- X
- X
- Xcfile *chook(f)
- XFILE *f; /* file stream */
- X/* Inherit the file stream structure and add a CRC and buffer for appending
- X a CRC on reads and checking the CRC on writes. Return a pointer to the
- X cfile structure, or NULL if the malloc() failed. Also, if MSDOS, set the
- X file mode to binary to avoid LF<->CRLF conversions. */
- X{
- X cfile *c; /* allocated cfile structure */
- X
- X#ifdef MSDOS
- X /* Set file mode to binary for MSDOS systems */
- X setmode(fileno(f), O_BINARY);
- X#endif /* MSDOS */
- X
- X /* Allocate and fill structure */
- X if ((c = (cfile *)malloc(sizeof(cfile))) != NULL)
- X {
- X c->f = f; /* file stream */
- X c->b = 0; /* empty fifo (for output) */
- X c->c = 0xffffffffL; /* preload CRC register */
- X c->n = 0; /* fifo is empty (output) or */
- X } /* no CRC bytes given (input) */
- X return c;
- X}
- X
- X
- X
- X/* cgetc(x)--like getc(f), but appends a 32-bit CRC to the end of the stream.
- X Return the byte read (the last four of which will be the CRC) or EOF. */
- X#define cgete(x) (x->n==4?EOF:(x->c=x->n++?x->c>>8:~x->c,(int)x->c&0xff))
- X#define cgetc(x) (x->n==0&&(b=getc(x->f))!=EOF?(ccnt++,x->c=CRC(x->c,b),b):cgete(c))
- X
- X
- X/* cputc(d,x)--like putc(d,f), but delays four bytes and computes a CRC.
- X x is a cfile *, and d is expected to be an ulg. */
- X#define cputf(x) (int)(x->c=CRC(x->c,x->b),putc((int)x->b&0xff,x->f),ccnt++)
- X#define cputc(d,x) (x->n!=4?x->n++:cputf(x),x->b=(x->b>>8)+((ulg)(d)<<24))
- X
- X
- Xchar *nopath(p)
- Xchar *p; /* full file name */
- X/* Extract just the name of file--remove and subdirectories or devices */
- X{
- X#ifdef MSDOS
- X char *q = "/\\:"; /* MSDOS delimiters */
- X#else /* !MSDOS */
- X#ifdef VMS
- X char *q = "]:"; /* VMS delimiters */
- X#else /* !VMS */
- X char *q = "/"; /* Unix delimiter */
- X#endif /* ?VMS */
- X#endif /* ?MSDOS */
- X char *r; /* result of strrchr() */
- X
- X while (*q)
- X if ((r = strrchr(p, *q++)) != NULL)
- X p = r + 1;
- X return p;
- X}
- X
- X
- Xvoid newship()
- X/* Open up a new ship file to write to */
- X{
- X int i; /* scans down name to increment */
- X
- X for (i = 7; i > 3; i--)
- X if (++sname[i] > '9')
- X sname[i] = '0';
- X else
- X break;
- X if (i == 3)
- X err(SE_MANY, "");
- X if ((sfile = fopen(mail ? mktemp(strcpy(mname, TMPNAME)) : sname,
- X "w")) == NULL)
- X err(SE_FULL, mail ? mname : sname);
- X slns = 0;
- X}
- X
- X
- Xvoid endship(e)
- Xint e; /* true if ending the last ship file */
- X/* Finish off current ship file */
- X{
- X char *s; /* malloc'd space for mail command */
- X
- X if (ferror(sfile) || fclose(sfile))
- X err(SE_FULL, mail ? mname : sname);
- X if (mail)
- X {
- X if ((s = malloc(strlen(MAILCMD)- 5*2 + strlen(mprefix) + strlen(sname) +
- X (e ? 7 : 0) + strlen(mdest) + strlen(mname) + 1)) == NULL)
- X err(SE_MEM, "");
- X#ifdef VMS
- X sprintf(s, MAILCMD, mname, mprefix, sname, e ? " (last)" : "", mdest);
- X if (!system(s)) /* this string fits on one line */
- X err(SE_MAIL, "system() call is not supported on this machine");
- X#else /* !VMS */
- X sprintf(s, MAILCMD, mprefix, sname, e ? " (last)" : "", mdest, mname);
- X if (system(s))
- X err(SE_MAIL, s);
- X#endif /* ?VMS */
- X free((voidp *)s);
- X unlink(mname);
- X *mname = 0;
- X }
- X}
- X
- X
- Xvoid newline(p)
- Xchar *p; /* name of the input file */
- X/* Add a new line inside a ship file, possibly cut the file */
- X{
- X putc('\n', sfile);
- X slns++;
- X if (slmax && slns >= slmax - 2)
- X {
- X putc('$', sfile);
- X if (fast)
- X fputs(" f", sfile);
- X fputs("\nmore\n", sfile);
- X endship(0);
- X newship();
- X fprintf(sfile, "$%s\ncont %lu %s\n", fast ? " f" : "", ccnt, nopath(p));
- X slns += 2;
- X }
- X}
- X
- X
- X/* Macro to avoid leading dots. It assumes i==0 at the beginning of a line
- X and that b is an available int. c is only evaluated once. */
- X#define sputc(c,f) (i==0?((b=(c))=='.'?putc(' ',f):0,putc(b,f)):putc(c,f))
- X
- X
- Xvoid ship(p, f)
- Xchar *p; /* name of the input file */
- XFILE *f; /* input file */
- X/* Encode the binary file f. */
- X{
- X int b; /* character just read */
- X cfile *c; /* checked file stream */
- X int i; /* how much is written on line so far */
- X int j; /* how much is in bit buffer */
- X
- X /* Set up output file if needed */
- X if ((mail || slmax) && sfile == stdout)
- X {
- X strcpy(sname, "part0000");
- X newship();
- X }
- X
- X /* Write header */
- X if ((c = chook(f)) == NULL)
- X err(SE_MEM, "");
- X ccnt = 0;
- X if (slmax && slns >= slmax - 5)
- X {
- X endship(0);
- X newship();
- X }
- X fprintf(sfile, "$%s\nship %s\n", fast ? " f" : "", nopath(p));
- X slns += 2;
- X
- X /* Encode the file, writing to sfile */
- X if (fast)
- X {
- X int d; /* accumulates bits (never more than 14) */
- X
- X d = j = i = 0;
- X while ((b = cgetc(c)) != EOF)
- X {
- X d |= b << j;
- X j += 8;
- X if ((d & 0x3f) >= LOWSZ)
- X {
- X sputc((int)(safe[(d & 0x3f) + LOWSZ]), sfile);
- X d >>= 6;
- X j -= 6;
- X }
- X else
- X {
- X sputc((int)(safe[(d & 0x3f) + (d & 0x40 ? LOWSZ : 0)]), sfile);
- X d >>= 7;
- X j -= 7;
- X }
- X if (++i == 79)
- X {
- X newline(p);
- X i = 0;
- X }
- X if (j >= 6 && (d & 0x3f) >= LOWSZ)
- X {
- X sputc((int)(safe[(d & 0x3f) + LOWSZ]), sfile);
- X d >>= 6;
- X j -= 6;
- X if (++i == 79)
- X {
- X newline(p);
- X i = 0;
- X }
- X }
- X else if (j >= 7)
- X {
- X sputc((int)(safe[(d & 0x3f) + (d & 0x40 ? LOWSZ : 0)]), sfile);
- X d >>= 7;
- X j -= 7;
- X if (++i == 79)
- X {
- X newline(p);
- X i = 0;
- X }
- X }
- X }
- X free((voidp *)c);
- X
- X /* Write leftover bits */
- X if (j)
- X {
- X sputc((int)(safe[d + (d < LOWSZ ? 0 : LOWSZ)]), sfile);
- X putc('\n', sfile);
- X slns++;
- X }
- X else if (i)
- X {
- X putc('\n', sfile);
- X slns++;
- X }
- X }
- X else
- X {
- X ulg d; /* accumulates bytes */
- X
- X d = j = i = 0;
- X while ((b = cgetc(c)) != EOF)
- X {
- X d += ((ulg)b) << j;
- X if ((j += 8) == 32)
- X {
- X sputc((int)(safe[(int)(d % 85)]), sfile); d /= 85;
- X putc((int)(safe[(int)(d % 85)]), sfile); d /= 85;
- X putc((int)(safe[(int)(d % 85)]), sfile); d /= 85;
- X putc((int)(safe[(int)(d % 85)]), sfile); d /= 85;
- X putc((int)(safe[(int)d]), sfile);
- X if (++i == 15) /* each line is <= 75 characters */
- X {
- X newline(p);
- X i = 0;
- X }
- X d = j = 0;
- X }
- X }
- X free((voidp *)c);
- X
- X /* Write leftover data */
- X if (j)
- X {
- X j >>= 3;
- X sputc((int)(safe[(int)(d % 85)]), sfile);
- X while (j--)
- X {
- X d /= 85;
- X putc((int)(safe[(int)(d % 85)]), sfile);
- X }
- X putc('\n', sfile);
- X slns++;
- X }
- X else if (i)
- X {
- X putc('\n', sfile);
- X slns++;
- X }
- X }
- X putc('$', sfile);
- X if (fast)
- X fputs(" f", sfile);
- X fputs("\nend\n", sfile);
- X slns += 2;
- X if (ferror(sfile) || fflush(sfile))
- X err(SE_FULL, mail ? mname : sname);
- X if (noisy)
- X fprintf(stderr, "%s shipped\n", p);
- X}
- X
- X
- Xvoid mkinv()
- X/* Build invsafe[], the inverse of safe[]. */
- X{
- X int i;
- X
- X for (i = 0; i < 256; i++)
- X invsafe[i] = 127;
- X for (i = 0; i < sizeof(safe); i++)
- X invsafe[safe[i]] = (char)i;
- X for (i = 0; aliases[i]; i += 2)
- X invsafe[aliases[i]] = invsafe[aliases[i + 1]];
- X}
- X
- X
- Xunsigned int decb; /* bit buffer for decode */
- Xunsigned int decn; /* number of bits in decb */
- X
- Xvoid decode(s, c)
- Xunsigned char *s; /* data to decode */
- Xcfile *c; /* binary output file */
- X/* Decode s, a string of base 85 digits or, if fast is true, a string of safe
- X characters generated arithmetically, into its binary equivalent, writing
- X the result to c, using cputc(). */
- X{
- X int b; /* state of line loop, next character */
- X int k; /* counts bits or digits read */
- X /* powers of 85 table for decoding */
- X static ulg m[] = {1L,85L,85L*85L,85L*85L*85L,85L*85L*85L*85L};
- X
- X if (fast)
- X {
- X unsigned int d; /* disperses bits */
- X
- X d = decb;
- X k = decn;
- X while ((b = *s++) != 0)
- X if ((b = invsafe[b]) < sizeof(safe))
- X {
- X if (b < LOWSZ)
- X {
- X d |= b << k;
- X k += 7;
- X }
- X else if ((b -= LOWSZ) < LOWSZ)
- X {
- X d |= (b + 0x40) << k;
- X k += 7;
- X }
- X else
- X {
- X d |= b << k;
- X k += 6;
- X }
- X if (k >= 8)
- X {
- X cputc(d, c);
- X d >>= 8;
- X k -= 8;
- X }
- X }
- X decb = d;
- X decn = k;
- X }
- X else
- X {
- X ulg d; /* disperses bytes */
- X
- X d = k = 0;
- X while ((b = *s++) != 0)
- X if ((b = invsafe[b]) < 85)
- X {
- X d += m[k] * b;
- X if (++k == 5)
- X {
- X cputc(d, c); d >>= 8;
- X cputc(d, c); d >>= 8;
- X cputc(d, c); d >>= 8;
- X cputc(d, c);
- X d = k = 0;
- X }
- X }
- X if (--k > 0)
- X {
- X while (--k)
- X {
- X cputc(d, c);
- X d >>= 8;
- X }
- X cputc(d, c);
- X }
- X }
- X}
- X
- X
- Xvoid unship(v, g, o)
- Xchar **v; /* arguments */
- Xint g; /* number of arguments */
- Xint o; /* overwrite flag */
- X/* Extract from the files named in the arguments the files that were
- X encoded by ship. If an argument is "-", then stdin is read. */
- X{
- X int b; /* state of line loop */
- X cfile *c; /* output binary file */
- X FILE *f; /* output file */
- X char *h; /* name of current ship file */
- X char l[LNSZ]; /* line buffer on input */
- X int n; /* next argument to use for input */
- X char *p; /* modifies line buffer */
- X char *q; /* scans continuation line */
- X char *r; /* name of output binary file */
- X FILE *s; /* current ship file */
- X int z; /* true if zero files received */
- X
- X /* Build inverse table */
- X mkinv();
- X
- X /* No input or output files initially */
- X s = NULL;
- X c = NULL;
- X h = r = NULL;
- X
- X /* Loop on input files' lines */
- X z = 1; /* none received yet */
- X n = 0; /* start with file zero */
- X b = 2; /* not in body yet */
- X while (1) /* return on end of last file */
- X {
- X /* Get next line from list of files */
- X while (s == NULL || fgets(l, LNSZ, s) == NULL)
- X {
- X if (s != NULL)
- X fclose(s);
- X if (n >= g)
- X {
- X if (c != NULL)
- X err(SE_PART, r);
- X else if (z)
- X err(SE_NONE, "");
- X return;
- X }
- X if (v[n][0] == '-')
- X if (v[n][1])
- X err(SE_ARG, v[n]);
- X else
- X {
- X h = "stream stdin";
- X s = stdin;
- X }
- X else
- X {
- X h = v[n];
- X if ((s = fopen(h, "r")) == NULL)
- X err(SE_FIND, h);
- X }
- X n++;
- X b &= ~1; /* not in middle of line */
- X }
- X
- X /* Strip control characters and leading blank space, if any */
- X for (q = l; *q && *q <= ' ' && *q != '\n'; q++)
- X ;
- X for (p = l; *q; q++)
- X if (*q >= ' ' || *q == '\n')
- X *p++ = *q;
- X *p = 0;
- X
- X /* Based on current state, end or start on terminator. States are:
- X b == 0: at start of body or body terminator line
- X b == 1: in middle of body line
- X b == 2: at start of non-body line
- X b == 3: in middle of non-body line
- X b == 4: at information line
- X */
- X switch (b)
- X {
- X case 0:
- X if ((!fast && strcmp(l, "$\n") == 0) ||
- X (fast && strcmp(l, "$ f\n") == 0))
- X {
- X b = 4;
- X break;
- X }
- X /* fall through to case 1 */
- X case 1:
- X decode((unsigned char *)l, c);
- X b = l[strlen(l) - 1] != '\n';
- X break;
- X case 2:
- X if (strcmp(l, "$\n") == 0 || strcmp(l, "$ f\n") == 0)
- X {
- X fast = l[1] == ' ';
- X b = 4;
- X break;
- X }
- X /* fall through to case 3 */
- X case 3:
- X b = l[strlen(l)-1] == '\n' ? 2 : 3;
- X break;
- X case 4:
- X /* Possible information lines are ship, more, cont, and end */
- X if (l[b = strlen(l) - 1] != '\n')
- X err(SE_FORM, h);
- X l[b] = 0;
- X if (strncmp(l, "ship ", 5) == 0)
- X {
- X /* get name, open new output file */
- X if (c != NULL)
- X err(SE_FORM, h);
- X if ((r = malloc(b - 4)) == NULL)
- X err(SE_MEM, "");
- X strcpy(r, l + 5);
- X if (strcmp(r, "-") == 0)
- X f = stdout;
- X#ifndef VMS /* shouldn't have explicit version #, so VMS won't overwrite */
- X else if (!o && (f = fopen(r, "r")) != NULL)
- X {
- X fclose(f);
- X err(SE_OVER, r);
- X }
- X#endif /* !VMS */
- X else if ((f = fopen(r, "w")) == NULL)
- X err(SE_FULL, r);
- X if ((c = chook(f)) == NULL)
- X err(SE_MEM, "");
- X b = decb = decn = 0;
- X ccnt = 0;
- X }
- X else if (strcmp(l, "more") == 0)
- X {
- X /* check if currently writing */
- X if (c == NULL)
- X err(SE_FORM, h);
- X b = 2;
- X }
- X else if (strncmp(l, "cont ", 5) == 0)
- X {
- X /* check name and file offset */
- X if (c == NULL)
- X err(SE_FORM, h);
- X for (q = l + 5; *q && *q != ' '; q++)
- X ;
- X if (*q == 0 || atol(l + 5) != ccnt + 4 + (decn != 0) ||
- X strcmp(q + 1, r))
- X err(SE_CONT, r);
- X b = 0;
- X }
- X else if (strcmp(l, "end") == 0)
- X {
- X /* check crc, close output file */
- X if (c == NULL)
- X err(SE_FORM, h);
- X if (c->n != 4 || c->b != ~c->c)
- X err(SE_CRC, r);
- X if (ferror(c->f) || fclose(c->f))
- X err(SE_FULL, r);
- X if (noisy)
- X fprintf(stderr, "%s received\n", r);
- X z = 0;
- X free((voidp *)c);
- X c = NULL;
- X b = 2;
- X }
- X else
- X {
- X for (q = l; *q && *q != ' '; q++)
- X ;
- X *q = 0;
- X fprintf(stderr, "%s: unsupported keyword '%s' ignored\n", warname, l);
- X b = 4;
- X }
- X break;
- X }
- X }
- X}
- X
- X
- Xvoid help()
- X{
- X int i;
- X static char *text[] = {
- X"Usage:",
- X" ship [-f] [-q] [-nnn] [-m address] [-s subject] files...",
- X"",
- X" ships the files to stdout. -m sends the output via the mailer to",
- X" address. -nnn splits the output into pieces of nnnK bytes or less.",
- X" if -nnn is used without -m, the output goes to the files partxxxx,",
- X" where xxxx is 0001, 0002, etc. If -0 is specified, the output goes",
- X" entirely to the file part0001. -f uses a fast method with slightly",
- X" less performance. If no files are given, stdin is used. The special",
- X" filename '-' also takes input from stdin. Files shipped from stdin",
- X" are unshipped to stdout. This can be used to document a shipment.",
- X" When mailing, -s gives a subject line prefix. -q inhibits messages.",
- X"",
- X" ship -u [-o] [-q] files...",
- X" unship [-o] [-q] files...",
- X"",
- X" extracts the contents of the mail messages in files... -o allows",
- X" existing files to be overwritten. -u is implied if the name of the",
- X" executable is unship. If no files are given, the input is from",
- X" stdin. If any of the files were shipped from stdin, then they are",
- X" extracted to stdout."
- X };
- X
- X puts(SHIPVER);
- X for (i = 0; i < sizeof(text)/sizeof(char *); i++)
- X {
- X printf(text[i]);
- X putchar('\n');
- X }
- X exit(0);
- X}
- X
- X
- Xvoid main(argc, argv)
- Xint argc; /* number of arguments */
- Xchar **argv; /* table of argument strings */
- X{
- X FILE *f; /* input file */
- X char *p; /* temporary variable */
- X int o; /* overwrite flag */
- X int r; /* temporary variable */
- X int s; /* true if no names given */
- X
- X /* No temporary file yet (for err()) */
- X *mname = 0;
- X
- X /* No subject prefix yet */
- X *mprefix = 0;
- X
- X /* See if help requested */
- X if (argc > 1 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-?") == 0))
- X help();
- X
- X /* Unship */
- X if ((p = strrchr(argv[0], PATHCUT)) == NULL)
- X p = argv[0];
- X else
- X p++;
- X r = 0; /* (make some compilers happier) */
- X if ((r = strncmp(p, "unship", 6)) == 0 ||
- X (r = strncmp(p, "UNSHIP", 6)) == 0 ||
- X (argc > 1 && strcmp(argv[1], "-u") == 0))
- X {
- X errname = "unship error";
- X warname = "unship warning";
- X r = r ? 2 : 1; /* next arg */
- X o = 0; /* disallow overwriting */
- X if (r < argc && strcmp(argv[r], "-o") == 0)
- X {
- X r++;
- X o = 1; /* allow overwriting */
- X }
- X if (r < argc && strcmp(argv[r], "-q") == 0)
- X {
- X r++;
- X noisy = 0; /* inhibit messages */
- X }
- X if (r < argc)
- X unship(argv + r, argc - r, o); /* unship files in args */
- X else
- X {
- X char *a[1]; /* short list of names (one) */
- X
- X a[0] = "-";
- X unship(a, 1, o); /* no args--do stdin */
- X }
- X }
- X
- X /* Ship */
- X else
- X {
- X mail = 0; /* not mailing */
- X fast = 0; /* use base 85 encoding */
- X s = 1; /* no names given yet */
- X strcpy(sname, "-"); /* output to stdout */
- X sfile = stdout;
- X slns = slmax = 0;
- X for (r = 1; r < argc; r++) /* go through args */
- X if (argv[r][0] == '-') /* option or stdin */
- X if (argv[r][1]) /* option */
- X {
- X if (argv[r][1] == 'm') /* mail output */
- X {
- X mail = 1;
- X mdest = NULL; /* next arg is mail address */
- X }
- X else if (argv[r][1] == 's') /* next arg is subject prefix */
- X mprefix = NULL;
- X else if (argv[r][1] == 'f') /* fast arithmetic encoding */
- X fast = 1;
- X else if (argv[r][1] == 'q') /* quiet operation */
- X noisy = 0;
- X else /* option is number of lines */
- X {
- X /* Check numeric option */
- X for (p = argv[r] + 1; *p; p++)
- X if (*p < '0' || *p > '9')
- X break;
- X if (*p || slmax)
- X err(SE_ARG, argv[r]);
- X
- X /* Zero means infinity, else convert */
- X if ((slmax = atol(argv[r] + 1)) == 0)
- X slmax = -1L;
- X else
- X {
- X long b;
- X
- X b = slmax * 1000L;
- X slmax = (int)(b / (fast ? 81 : 77));
- X /* Note: five of the lines aren't that long, but that
- X leaves some slack for mail headers, etc. Also, note
- X that we conservatively assume 1000 bytes/K and two
- X bytes per new line. */
- X }
- X }
- X }
- X else /* input file is stdin */
- X {
- X if (mail && mdest == NULL)
- X err(SE_ARG, "- (no mail destination given)");
- X s = 0;
- X if (mail && !*mprefix)
- X strcpy(mprefix, "(stdin)");
- X ship("-", stdin);
- X }
- X else /* not option or stdin */
- X if (mail && mdest == NULL) /* arg is mail address */
- X mdest = argv[r];
- X else if (mprefix == NULL) /* arg is subject prefix */
- X mprefix = argv[r];
- X else /* arg is file to ship */
- X {
- X s = 0;
- X if ((f = fopen(argv[r], "r")) == NULL)
- X err(SE_FIND, argv[r]);
- X if (mail && !*mprefix)
- X {
- X int i;
- X
- X for (i = 0, p = nopath(argv[r]); i < 8 && *p; p++)
- X if ((*p >= '0' && *p <= '9') || (*p >= 'A' && *p <= 'Z') ||
- X (*p >= 'a' && *p <= 'z') || *p == '.' || *p == '_')
- X mprefix[i++] = *p;
- X mprefix[i] = 0;
- X }
- X ship(argv[r], f);
- X fclose(f);
- X }
- X if (s) /* no names--act as filter */
- X if (mail && mdest == NULL)
- X err(SE_ARG, "-m (no mail destination given)");
- X else if (mprefix == NULL)
- X err(SE_ARG, "-s (no subject prefix given)");
- X else
- X {
- X if (mail && !*mprefix)
- X strcpy(mprefix, "(stdin)");
- X ship("-", stdin);
- X }
- X endship(1); /* clean up */
- X if (noisy && (mail || slmax))
- X fprintf(stderr, "file%s%s %s\n",
- X strcmp("part0001", sname) ? "s part0001.." : " ", sname,
- X mail ? "mailed" : "written");
- X }
- X
- X /* Done */
- X exit(0);
- X}
- END_OF_FILE
- if test 38393 -ne `wc -c <'ship.c'`; then
- echo shar: \"'ship.c'\" unpacked with wrong size!
- fi
- # end of 'ship.c'
- fi
- if test -f 'util.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'util.c'\"
- else
- echo shar: Extracting \"'util.c'\" \(10800 characters\)
- sed "s/^X//" >'util.c' <<'END_OF_FILE'
- X/*
- X
- X Copyright (C) 1990,1991 Mark Adler, Richard B. Wales, and Jean-loup Gailly.
- X Permission is granted to any individual or institution to use, copy, or
- X redistribute this software so long as all of the original files are included
- X unmodified, that it is not sold for profit, and that this copyright notice
- X is retained.
- X
- X*/
- X
- X/*
- X * util.c by Mark Adler.
- X */
- X
- X#include "zip.h"
- X
- X/* Local functions */
- X#ifdef PROTO
- X local int recmatch(char *, char *);
- X#endif /* PROTO */
- X
- X
- Xchar *isshexp(p)
- Xchar *p; /* candidate sh expression */
- X/* If p is a sh expression, a pointer to the first special character is
- X returned. Otherwise, NULL is returned. */
- X{
- X int c;
- X
- X c = -1;
- X for (; *p; p++)
- X#ifdef VMS
- X if (c != '\\' && (*p == '%' || *p == '*'))
- X#else /* !VMS */
- X if (c != '\\' && (*p == '?' || *p == '*' || *p == '['))
- X#endif /* ?VMS */
- X return p;
- X return NULL;
- X}
- X
- X
- Xlocal int recmatch(p, s)
- Xchar *p; /* sh pattern to match */
- Xchar *s; /* string to match it to */
- X/* Recursively compare the sh pattern p with the string s and return 1 if
- X they match, and 0 or 2 if they don't or if there is a syntax error in the
- X pattern. This routine recurses on itself no deeper than the number of
- X characters in the pattern. */
- X{
- X int c; /* pattern char or start of range in [-] loop */
- X
- X /* Get first character, the pattern for new recmatch calls follows */
- X c = *p++;
- X
- X /* If that was the end of the pattern, match if string empty too */
- X if (c == 0)
- X return *s == 0;
- X
- X /* '?' (or '%') matches any character (but not an empty string) */
- X#ifdef VMS
- X if (c == '%')
- X#else /* !VMS */
- X if (c == '?')
- X#endif /* ?VMS */
- X return *s ? recmatch(p, s + 1) : 0;
- X
- X /* '*' matches any number of characters, including zero */
- X if (c == '*')
- X {
- X if (*p == 0)
- X return 1;
- X for (; *s; s++)
- X if ((c = recmatch(p, s)) != 0)
- X return c;
- X return 2; /* 2 means give up--shmatch will return false */
- X }
- X
- X#ifndef VMS /* No bracket matching in VMS */
- X /* Parse and process the list of characters and ranges in brackets */
- X if (c == '[')
- X {
- X int e; /* flag true if next char to be taken literally */
- X char *q; /* pointer to end of [-] group */
- X int r; /* flag true to match anything but the range */
- X
- X if (*s == 0) /* need a character to match */
- X return 0;
- X p += (r = *p == '!'); /* see if reverse */
- X for (q = p, e = 0; *q; q++) /* find closing bracket */
- X if (e)
- X e = 0;
- X else
- X if (*q == '\\')
- X e = 1;
- X else if (*q == ']')
- X break;
- X if (*q != ']') /* nothing matches if bad syntax */
- X return 0;
- X for (c = 0, e = *p == '-'; p < q; p++) /* go through the list */
- X {
- X if (e == 0 && *p == '\\') /* set escape flag if \ */
- X e = 1;
- X else if (e == 0 && *p == '-') /* set start of range if - */
- X c = *(p-1);
- X else
- X {
- X if (*(p+1) != '-')
- X for (c = c ? c : *p; c <= *p; c++) /* compare range */
- X#ifdef OS2
- X if (tolower(c) == tolower(*s))
- X#else /* !OS2 */
- X if (c == *s)
- X#endif /* ?OS2 */
- X return r ? 0 : recmatch(q + 1, s + 1);
- X c = e = 0; /* clear range, escape flags */
- X }
- X }
- X return r ? recmatch(q + 1, s + 1) : 0; /* bracket match failed */
- X }
- X#endif /* !VMS */
- X
- X /* If escape ('\'), just compare next character */
- X if (c == '\\')
- X if ((c = *p++) == 0) /* if \ at end, then syntax error */
- X return 0;
- X
- X /* Just a character--compare it */
- X#ifdef OS2
- X return tolower(c) == tolower(*s) ? recmatch(p, ++s) : 0;
- X#else /* !OS2 */
- X return c == *s++ ? recmatch(p, s) : 0; /* compare one character */
- X#endif /* ?OS2 */
- X}
- X
- X
- Xint shmatch(p, s)
- Xchar *p; /* sh pattern to match */
- Xchar *s; /* string to match it to */
- X/* Compare the sh pattern p with the string s and return true if they match,
- X false if they don't or if there is a syntax error in the pattern. */
- X{
- X return recmatch(p, s) == 1;
- X}
- X
- X
- X#ifdef MSDOS
- X
- Xint dosmatch(p, s)
- Xchar *p; /* dos pattern to match */
- Xchar *s; /* string to match it to */
- X/* Break the pattern and string into name and extension parts and match
- X each separately using shmatch(). */
- X{
- X char *p1, *p2; /* pattern sections */
- X char *s1, *s2; /* string sections */
- X int r; /* result */
- X
- X if ((p1 = malloc(strlen(p) + 1)) == NULL ||
- X (s1 = malloc(strlen(s) + 1)) == NULL)
- X {
- X if (p1 != NULL)
- X free((voidp *)p1);
- X return 0;
- X }
- X strcpy(p1, p);
- X strcpy(s1, s);
- X if ((p2 = strrchr(p1, '.')) != NULL)
- X *p2++ = 0;
- X else
- X p2 = "";
- X if ((s2 = strrchr(s1, '.')) != NULL)
- X *s2++ = 0;
- X else
- X s2 = "";
- X r = shmatch(p2, s2) && shmatch(p1, s1);
- X free((voidp *)p1);
- X free((voidp *)s1);
- X return r;
- X}
- X
- X#endif /* MSDOS */
- X
- X
- Xvoidp far **search(b, a, n, cmp)
- Xvoidp *b; /* pointer to value to search for */
- Xvoidp far **a; /* table of pointers to values, sorted */
- Xextent n; /* number of pointers in a[] */
- Xint (*cmp) OF((voidp *, voidp far *)); /* comparison function for search */
- X/* Search for b in the pointer list a[0..n-1] using the compare function
- X cmp(b, c) where c is an element of a[i] and cmp() returns negative if
- X *b < *c, zero if *b == *c, or positive if *b > *c. If *b is found,
- X search returns a pointer to the entry in a[], else search() returns
- X NULL. The nature and size of *b and *c (they can be different) are
- X left up to the cmp() function. A binary search is used, and it is
- X assumed that the list is sorted in ascending order. */
- X{
- X voidp far **i; /* pointer to midpoint of current range */
- X voidp far **l; /* pointer to lower end of current range */
- X int r; /* result of (*cmp)() call */
- X voidp far **u; /* pointer to upper end of current range */
- X
- X l = (voidp far **)a; u = l + (n-1);
- X while (u >= l)
- X if ((r = (*cmp)(b, *(i = l + ((u - l) >> 1)))) < 0)
- X u = i - 1;
- X else if (r > 0)
- X l = i + 1;
- X else
- X return (voidp far **)i;
- X return NULL; /* If b were in list, it would belong at l */
- X}
- X
- X
- X
- X/* Table of CRC-32's of all single byte values (made by makecrc.c) */
- Xlocal ulg crctab[] = {
- X 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
- X 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
- X 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
- X 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
- X 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
- X 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
- X 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
- X 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
- X 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
- X 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
- X 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
- X 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
- X 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
- X 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
- X 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
- X 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
- X 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
- X 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
- X 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
- X 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
- X 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
- X 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
- X 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
- X 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
- X 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
- X 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
- X 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
- X 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
- X 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
- X 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
- X 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
- X 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
- X 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
- X 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
- X 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
- X 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
- X 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
- X 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
- X 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
- X 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
- X 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
- X 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
- X 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
- X 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
- X 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
- X 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
- X 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
- X 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
- X 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
- X 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
- X 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
- X 0x2d02ef8dL
- X};
- X
- X
- Xulg crc32(c, b)
- Xulg c; /* current contents of crc shift register */
- Xint b; /* byte (eight bits) to run through */
- X/* Return the CRC-32 c updated with the eight bits in b. */
- X{
- X return crctab[((int)c ^ b) & 0xff] ^ (c >> 8);
- X}
- X
- X
- Xulg updcrc(s, n)
- Xchar *s; /* pointer to bytes to pump through */
- Xextent n; /* number of bytes in s[] */
- X/* Run a set of bytes through the crc shift register. If s is a NULL
- X pointer, then initialize the crc shift register contents instead.
- X Return the current crc in either case. */
- X{
- X register ulg c; /* temporary variable */
- X
- X static ulg crc = 0xffffffffL; /* shift register contents */
- X
- X if (s == NULL)
- X c = 0xffffffffL;
- X else
- X {
- X c = crc;
- X while (n--)
- X c = crctab[((int)c ^ (*s++)) & 0xff] ^ (c >> 8);
- X }
- X crc = c;
- X return c ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */
- X}
- END_OF_FILE
- if test 10800 -ne `wc -c <'util.c'`; then
- echo shar: \"'util.c'\" unpacked with wrong size!
- fi
- # end of 'util.c'
- fi
- echo shar: End of archive 3 \(of 9\).
- cp /dev/null ark3isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 9 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-